#ifndef LIBACCENT_ALGORITHMS_DROP_WHILE_HPP
#define LIBACCENT_ALGORITHMS_DROP_WHILE_HPP

#include "accent/algorithms/zip.hpp"
#include "accent/functional/equals.hpp"
#include "accent/functional/not.hpp"
#include <boost/fusion/functional/generation/make_fused.hpp>
#include <utility>

namespace accent
{

  template <typename Range, typename Predicate>
  Range drop_while(Range r, Predicate p) {
    while (!r.empty() && p(r.front()))
      r.pop_front();
    return r;
  }

  template <typename Range, typename Predicate>
  Range drop_until(Range r, Predicate p) {
    return drop_while(r, not_(p));
  }

  template <typename Range1, typename Range2, typename Predicate>
  std::pair<Range1, Range2> drop_matching(Range1 r1, Range2 r2, Predicate p) {
    auto v = drop_while(zip(r1, r2), boost::fusion::make_fused(p)).ranges();
    return std::make_pair(front(v), back(v));
  }

  template <typename Range1, typename Range2>
  std::pair<Range1, Range2> drop_matching(Range1 r1, Range2 r2) {
    return drop_matching(r1, r2, equals());
  }

}

#endif
